<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>判断数据类型</title>
</head>
<body>
<script>
/**
 * [isType 判断数据类型]
 * @param  {[type]} val  [description]
 * @param  {[type]} type 可判断类型：undefined、null、string、number、boolean、array、object、symbol、date、regexp、function、asyncfunction、arguments、set、map、weakset、weakmap
 * @return {[boolean]}      [description]
 */
function isType(val, type) {
	const dataType = Object.prototype.toString.call(val).replace(/\[object (\w+)\]/, "$1").toLowerCase();
	return type ? dataType === type : dataType;
}
console.log(isType("young")); // "string"
console.log(isType(20190214)); // "number"
console.log(isType(true)); // "boolean"
console.log(isType([], "array")); // true
console.log(isType({}, "array")); // false
</script>	
</body>
</html>